package com.ncp.model.biz.index;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.ncp.model.dao.DbConnection;
import com.ncp.model.entity.index.FootBean;

public class FootManager {
	private Connection ct=null;
	private PreparedStatement ps=null;
	private ResultSet rs=null;
	//根据id从数据库取出尾部信息
	public FootBean getInfo(String id){
		FootBean fb=new FootBean();
		try {
			ct = DbConnection.getConnByDataSource();
			String sql="select * from FOOT where FOOTID="+id;
			ps=ct.prepareStatement(sql);
			rs=ps.executeQuery();
			if(rs.next()){
				fb.setId(rs.getInt(1));
				fb.setAddress(rs.getString(2));
				fb.setTelephone(rs.getString(3));
				fb.setFax(rs.getString(4));
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}finally{
			this.closeResource();
		}
		return fb;
	}
	//向数据库插入/编辑尾部信息
	public boolean updateFoot(String address,String telephone,String fax){
		boolean b=false;
		try {
			ct = DbConnection.getConnByDataSource();
			String sql="update FOOT set address='"+address+"',telephone='"+telephone+"',fax='"+fax+"' where FOOTID="+1;
			ps=ct.prepareStatement(sql);
			int num=ps.executeUpdate();
			if(num==1){
				b=true;
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}finally{
			this.closeResource();
		}
		return b;
	}
	//关闭资源
	public void closeResource(){
		try {
			if(rs!=null){
				rs.close();
				rs=null;
			}
			if(ps!=null){
				ps.close();
				ps=null;
			}
			if(ct!=null){
				ct.close();
				ct=null;
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}
